XPTemplate priority=sub

" Setting priority of cpp to "sub" or "subset of language", makes it override
" all c snippet if conflict



XPTvar $TRUE          true
XPTvar $FALSE         false
XPTvar $NULL          NULL

XPTvar $IF_BRACKET_STL     \n
XPTvar $FOR_BRACKET_STL    \n
XPTvar $WHILE_BRACKET_STL  \n
XPTvar $STRUCT_BRACKET_STL \n
XPTvar $FUNC_BRACKET_STL   \n

XPTvar $VOID_LINE  /* void */;
XPTvar $CURSOR_PH      /* cursor */

XPTvar $CL  /*
XPTvar $CM   *
XPTvar $CR   */

XPTvar $CS   //



XPTinclude
      \ _common/common
      \ _comment/singleDouble
      \ _condition/c.like
      \ _func/c.like
      \ _loops/c.while.like
      \ _loops/java.for.like
      \ _preprocessor/c.like
      \ _structures/c.like
XPTinclude
            \ c/c

" ========================= Function and Varaibles =============================
let s:f = g:XPTfuncs() 

function! s:f.cleanTempl( ctx, ... )
  let notypename = substitute( a:ctx,"\\s*typename\\s*","","g" )
  let cleaned = substitute( notypename, "\\s*class\\s*", "", "g" )
  return cleaned
endfunction


" ================================= Snippets ===================================
XPTemplateDef

"XPT all  hint=...begin,\ ...end,
"`v^.begin(), `v^.end(), `cursor^


"XPT vector hint=std::vector<..>\ ..;
"std::vector<`type^> `var^;
"`cursor^


"XPT map hint=std::map<..,..>\ ..;
"std::map<`typeKey^,`val^>   `name^;
"`cursor^


XPT class   hint=class+ctor indent=keep
class `className^
{
public:
    `className^( `ctorParam^ );
    ~`className^();
    `className^( const `className^ &cpy );
    `cursor^
private:
};
 
`className^::`className^( `ctorParam^ )
{
}
 
`className^::~`className^()
{
}
 
`className^::`className^( const `className^ &cpy )
{
}
..XPT


XPT namespace hint=namespace\ {}
namespace `name^
{
    `cursor^
}
..XPT


XPT templateclass   hint=template\ <>\ class
template
    <`templateParam^>
class `className^
{
public:
    `className^( `ctorParam^ );
    ~`className^();
    `className^( const `className^ &cpy );
    `cursor^
private:
};
 
template <`templateParam^>
`className^<`_^cleanTempl(R('templateParam'))^^>::`className^( `ctorParam^ )
{
}
 
template <`templateParam^>
`className^<`_^cleanTempl(R('templateParam'))^^>::~`className^()
{
}
 
template <`templateParam^>
`className^<`_^cleanTempl(R('templateParam'))^^>::`className^( const `className^ &cpy )
{
}
..XPT

XPT try hint=try\ ...\ catch...
XSET handler=$CL void $CR
try
{
    `what^
}`...^
catch ( `except^ )
{
    `handler^
}`...^



XPT try_ hint=try\ {\ SEL\ }\ catch...
XSET handler=$CL void $CR
try
{
    `wrapped^
}
`...^catch ( `except^ )
{
    `handler^
}
`...^

..XPT


" *************************
" My Additions/Replacements
" *************************

XPT inc		hint=include\ <>
#include <`iostream^>`cursor^

" Quick-Repetition parameters list
XPT def		hint=func..\ (\ ..\ )\ {...
XSET p..|post=ExpandIfNotEmpty(', ', 'p..')
`int^ `name^(`p..^)
{
    `cursor^
}

" Function Declaration
XPT defd	hint=func..\ (\ ..\ );
XSET p..|post=ExpandIfNotEmpty(', ', 'p..')
`int^ `name^(`p..^);`cursor^

XPT using hint=using\ namespace\ ...
using namespace `std^;`cursor^

XPT t hint=(...)\ ?\ ...\ :\ ...
(`/*test*/^) ? `/*a*/^ : `/*b*/^ `cursor^

XPT while  hint=while\ (...)\ {\ ...\ }
while (`/* condition */^) {
    `cursor^
}

XPT for hint=for\ (..;..;++)
for (int `i^ = `0^; `i^ < `n^; `i^++) {
    `cursor^
}

XPT ford hint=for\ (..;..;--)
for (`i^ = `n^; `i^ >`^=^ `0^; `i^--) {
    `cursor^
}

XPT fori hint=for\ (..::iterator;..;++)
for (`cont^<`T^>::iterator `it^ = `var^.begin(); `it^ != `var^.end(); `it^++) {
    `cursor^
}

XPT forr hint=for\ (..::reverse_iterator;..;++)
for (`cont^<`T^>::reverse_iterator `it^ = `var^.rbegin(); `it^ != `var^.rend(); `it^++) {
    `cursor^
}

"For Each
XPT fore hint=foreach
for (__typeof((`var^).begin()) `it^ = (`var^).begin(); `it^ != (`var^).end(); `it^++) {
    `cursor^
}

" Indexing
XPT d hint=[..]
[`0^]`cursor^

" Typedef
XPT td hint=typedef\ ...\ ...;
typedef `int^ `typeName^;`cursor^

" ************
" Input/Output
" ************

" simple cout
XPT cout hint=cout\ <<\ ...\ <<\ endl;
cout << `^ << endl;`cursor^

" single string cout
XPT scout hint=cout\ <<\ "..."\ <<\ endl;
cout << "`^" << endl;`cursor^

" string/variable alternate cout
XPT acout hint=cout\ <<\ "..."\ <<\ ... <<\ endl;
cout << "`^" << `^ ``...^<< " `^" << `^ `...^<< endl;`cursor^

" variable cout
XPT vcout hint=cout\ <<\ "var:"\ <<\ var\ <<\ ...\ <<\ endl;
cout << "`var^:" << `var^ ``...^<< " `var^:" << `var^ `...^<< endl;`cursor^

XPT cin hint=cin\ >>\ ...\;
cin >> `^``...^>> `^ `...^;`cursor^

XPT getline hint=getline
getline(`cin^, `var^, '\n');`cursor^

XPT fprintf hint=fprintf
XSET p..|post=ExpandIfNotEmpty(', ', 'p..')
fprintf(`fout^, "`%d^", `p..^);`cursor^

XPT fscanf hint=fscanf
XSET q..|post=ExpandIfNotEmpty(', ', '`&^`q..^')
fscanf(`fin^, "`%d^", `&^`q..^);`cursor^

XPT printf hint=printf
XSET p..|post=ExpandIfNotEmpty(', ', 'p..')
printf("`%d^", `p..^);`cursor^

XPT scanf hint=scanf
XSET q..|post=ExpandIfNotEmpty(', ', '`&^`q..^')
scanf("`%d^", `&^`q..^);`cursor^

"Types
XPT all  hint=...begin,\ ...end,
`v^.begin(), `v^.end()`cursor^
 
XPT vector hint=vector<..>\ ..;
vector<`type^> `var^;`cursor^

XPT pair hint=pair<..,..>\ ..;
pair<`first^, `second^> `var^;`cursor^

XPT map hint=map<..,..>\ ..;
map<`typeKey^,`val^> `name^;`cursor^

XPT ost hint=ostream_iterator<..>(cout, "..");
ostream_iterator<`int^>(`cout^, "`, ^")`cursor^

XPT ist hint=istream_iterator<..>(cin, "..");
istream_iterator<`int^>(`cin^)`cursor^

XPT ui
unsigned int`cursor^

XPT ul
unsigned long int`cursor^

XPT ull
unsigned long long int`cursor^

XPT li
long int`cursor^

XPT ll
long long int`cursor^

XPT ld
long double`cursor^

XPT pii
pair<int,int>`cursor^

XPT vpii
vector< pair<int,int> >`cursor^

XPT vi
vector<int>`cursor^

XPT vs
vector<string>`cursor^

XPT iss
istringstream`cursor^

XPT oss
ostringstream`cursor^

XPT template
template<typename `T^>
`cursor^

XPT f
first`cursor^

XPT s
second`cursor^

XPT mp
make_pair(`var^)`cursor^

XPT pb
push_back(`var^);`cursor^

XPT pf
push_front(`var^);`cursor^

XPT si
`var^.size()`cursor^
